package com.sj.common.utils;


import com.sj.common.config.CommonProperties;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("IdGenerator")
public class IdGenerator {
    @Resource
    CommonProperties commonProperties;

    public IdGenerator() {
    }

    /*public Long next(String key) {
        if (!StringUtils.isEmpty(this.commonProperties.getPre_key())) {
            key = this.commonProperties.getPre_key() + "." + key;
        }

        if ("default".equals(this.commonProperties.getType())) {
            return this.commonProperties.f(key);
        } else if ("sf".equals(this.commonProperties.getType())) {
            return this.commonProperties.e(key);
        } else {
            throw new UnsupportedOperationException(this.commonProperties.getType() + "  not supported!");
        }
    }

    public List<Object> nextList(String key, int size) throws Exception {
        if (size > this.commonProperties.getStep()) {
            throw new Exception();
        } else {
            if (!StringUtils.isEmpty(this.commonProperties.getPre_key())) {
                key = this.commonProperties.getPre_key() + "." + key;
            }

            if ("default".equals(this.commonProperties.getType())) {
                return this.a.nextList(key, size);
            } else if (!"sf".equals(this.commonProperties.getType())) {
                throw new UnsupportedOperationException(this.commonProperties.getType() + "  not supported!");
            } else {
                List<Object> currentList = new ArrayList();

                for(int i = 0; i < size; ++i) {
                    currentList.add(this.b.e(key));
                }

                return currentList;
            }
        }
    }*/
}
